<?php
include("../connection/connection.php");
//include("reportFunctions.php");
//$distId=418;//$_REQUEST['distId']
$sqlReport = "SELECT distinct `district_id`,`district_name` FROM `tbl_lookup_location`";
$queryReport = mysql_query($sqlReport);

function getCountQ($distId,$ques)
{
$queryForm="SELECT count(form_id) FROM $ques where district_id='".$distId."'" ;
$resultForm=mysql_query($queryForm);
$x=mysql_fetch_row($resultForm);
return $x[0];
}
function getCountUFW($distId,$ques)
{
$queryForm="SELECT count(form_id) FROM $ques where multi_dist_id='".$distId."'" ;
$resultForm=mysql_query($queryForm);
$x=mysql_fetch_row($resultForm);
return $x[0];
}
function getCountRWSS($distId)
{
$queryForm1="SELECT count(form_id) FROM tbl_dtls_q1_main where type_scheme='RWSS' and district_id='".$distId."'" ;
$resultForm1=mysql_query($queryForm1);
$x1=mysql_fetch_row($resultForm1);
return $x1[0];
}


?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Report</title>
</head>
<body>
<table border="0" width="800" cellspacing="0" cellpadding="0">
	<tr>
		<td bgcolor="#E9E9E9" height="26">
		<p align="center">
		<font face="Verdana" style="font-size: 9pt; font-weight: 700" color="#224568">
		Questionnaire wise reports for all districts </font>
		<div align="center"><span style="font-size: 9pt; font-weight: 700">
	        <font face="Verdana" color="#224568"> Table 1</font></span></div></td>
	</tr>
	<tr>
		<td bgcolor="#E9E9E9" height="56">
		<table border="1" width="800" cellspacing="0" cellpadding="0" height="49">
			
			<tr bgcolor="#C5D8EB">
			  <td width="119" align="center">
				<p align="center"><font face="Verdana" style="font-size: 8.5pt">
				Name of district</font></td>
				<td align="center" width="124">
				<font style="font-size: 8.5pt" face="Verdana">Q1</font></td>
				<td align="center" width="127">
				<font style="font-size: 8.5pt" face="Verdana">Q2</font></td>
				<td align="center" width="119">
				<font style="font-size: 8.5pt" face="Verdana">Q3</font></td>
				<td align="center" width="119"><font style="font-size: 8.5pt" face="Verdana">Critical Villages</font></td>
				<td align="center" width="119">
				<font style="font-size: 8.5pt" face="Verdana">RWSS</font></td>
			    <td align="center" width="119"><font style="font-size: 8.5pt" face="Verdana">UFW</font></td>
			</tr>
		 <?php  	
		 	while($rowReport = mysql_fetch_array($queryReport)) {
			
			?>
			<tr bgcolor="#FFFFFF">
				<td width="119" align="center"><font face="Verdana" style="font-size: 8.5pt">
				<?php
				echo $rowReport['district_name'];
				$Q1=getCountQ($rowReport['district_id'],'tbl_dtls_q1_main');
				$Q2=getCountQ($rowReport['district_id'],'tbl_dtls_q2_main');
				$Q3=getCountQ($rowReport['district_id'],'tbl_dtls_q3_loc');
				$crit=getCountQ($rowReport['district_id'],'tbl_dtls_critical');
				$rwss=getCountRWSS($rowReport['district_id']);
				$ufw=getCountUFW($rowReport['district_id'],'tbl_dtls_ufw_main');
				$TotalQ1=$Q1+$TotalQ1;
				$TotalQ2=$Q2+$TotalQ2;
				$TotalQ3=$Q3+$TotalQ3;
				$TotalCrit=$crit+$TotalCrit;
				$TotalRwss=$rwss+$TotalRwss;
				$TotalUfw=$ufw+$TotalUfw;
				$Grand=$TotalQ1+$TotalQ2+$TotalQ3+$TotalCrit+$TotalRwss+$TotalUfw;
				 ?>
				</font></td>
				<td width="124" align="center"><font face="Verdana" style="font-size: 8.5pt"><?php echo $Q1;?></font></td>
				<td width="127" align="center"><font face="Verdana" style="font-size: 8.5pt"><?php echo $Q2;?></font></td>
				<td align="center" width="119"><font face="Verdana" style="font-size: 8.5pt"><?php echo $Q3;?></font></td>
				<td align="center" width="119" ><font face="Verdana" style="font-size: 8.5pt"><?php echo $crit;?></font></td>
				<td align="center" width="119" ><font face="Verdana" style="font-size: 8.5pt"><?php echo $rwss;?></font></td>
			    <td align="center" width="119" ><font face="Verdana" style="font-size: 8.5pt"><?php echo $ufw;?></font></td>
			</tr>
			<?php
			}
			?>
			<tr bgcolor="#C5D8EB">
				<td width="119" align="center"><font face="Verdana" style="font-size: 9.5pt">Total</font></td>
				<td width="124" align="center"><font face="Verdana" style="font-size: 9.5pt"><?php echo $TotalQ1;?></font></td>
				<td width="127" align="center"><font face="Verdana" style="font-size: 9.5pt"><?php echo $TotalQ2;?></font></td>
				<td align="center" width="119"><font face="Verdana" style="font-size: 9.5pt"><?php echo $TotalQ3;?></font></td>
				<td align="center"><font face="Verdana" style="font-size: 9.5pt"><?php echo $TotalCrit;?></font></td>
				<td align="center"><font face="Verdana" style="font-size: 9.5pt"><?php echo $TotalRwss;?></font></td>
			    <td align="center"><font face="Verdana" style="font-size: 9.5pt"><?php echo $TotalUfw;?></font></td>
			</tr>
			<tr bgcolor="#E9E9E9">
			  <td align="center"><font face="Verdana" style="font-size: 9.5pt"><b>Grand Total</b></font></td>
			  <td colspan="6" align="center"><font face="Verdana" style="font-size: 9.5pt"><b><?php echo $Grand;?></b></font></td>
		  </tr>
		</table>
		</td>
	</tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>